package com.eastcom.providor.service.impl;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.Map;


import com.eastcom.bm.atom.DataAbnormal;
import com.eastcom.bm.atom.RawData;
import com.eastcom.common.util.CharliDate;
import com.eastcom.providor.dao.IDataAbnormalDao;
import com.eastcom.providor.dao.IRawDataDao;
import com.eastcom.providor.service.BaseService;
import com.eastcom.providor.service.IRawDataService;
import com.eastcom.providor.service.extview.DataAbnormalUtil;
import com.eastcom.providor.service.extview.RawDataUtil;

public class RawDataService extends BaseService implements IRawDataService {

	private IRawDataDao rawDataDao;
	
	private IDataAbnormalDao dataAbnormalDao;
	
	public void setRawDataDao(IRawDataDao rawDataDao) {
		this.rawDataDao = rawDataDao;
	}
	

	public void setDataAbnormalDao(IDataAbnormalDao dataAbnormalDao) {
		this.dataAbnormalDao = dataAbnormalDao;
		
	}

	/*
	public List<RawData> getRawDatasByDataSetId(String dataSetID,Date startDate, Date endDate) {
		// TODO Auto-generated method stub
		try{
			//IRawDataDao rawDao=DAOFactory.getInstance().getRawDataDao();
			List<RawData> list = rawDataDao.getRawDatasByDataSetId(dataSetID, startDate, endDate);
			return list;
		}
		catch(Exception e){
			log.error("IRawDataService getRawDatasByDataSetId error",e);
		}
		/*
		finally{
			JDBCTemplate.doSessionFinally();
		}
		
		return null;
	}
*/
	
	public List<Map<String,Object>> getRawDatasByDataSetIdsAndTime(String[] datasetIds,Date start,Date end){
		try{
		    List<RawData> rawDatas=null;
		    List<Map<String,Object>>  ret=new ArrayList<Map<String,Object>>();
		    if(datasetIds==null||datasetIds.length<=0)
			     rawDatas=rawDataDao.getAllCurrentRawDatas();
		
		    rawDatas=rawDataDao.getRawDatasByDataSetIds(datasetIds, start, end);
		
		    for(RawData rd:rawDatas){
			    ret.add(RawDataUtil.createRawDataBeanByRawData(rd));
		    }
		    
		    return ret;
		}
		catch(Exception e){
			
		}
		return null;
	}
	
	public List<Map<String,Object>> getWholeAbnormalRawDatasByDataset(String datasetID,Date time){
		List<Map<String, Object>> retVal=new ArrayList<Map<String,Object>>();
		try{
			Calendar calendar = Calendar.getInstance();
			if(datasetID==null||time==null)
				return null;
			calendar.setTime(time);
			Date start = CharliDate.getStartTimeOfCurrentDay(time);
			Date end = CharliDate.getStartTimeOfDaysApartCurrentDay(start, 1);
			
			
			List<RawData> list=rawDataDao.getAbnormalRawDatas(datasetID, start, end);
			
			for(RawData da:list){
				retVal.add(RawDataUtil.createRawDataBeanByRawData(da));
			}
			return retVal;
			
		}catch (Exception e) {
			e.printStackTrace();
			log.debug("DataAbnormalService.getWholeAbnormalRawDatasByDataset  is Error",e);
		}
		return retVal;
	}
	

	
	

}
